#include<bits/stdc++.h>
using namespace std;
const int maxm = 100000+7;
int que[maxm], head, tail;

int main() {
  int m; cin>>m;
  head = tail = 0;
  while(m--) {
    string op; cin>>op;
    if("push"==op) {
      int x; cin>>x;
      que[tail++] = x;
    }
    else if("pop"==op) {
      head++;
    }
    else if("empty"==op) {
      if(head==tail) {
        cout<<"YES\n";
      }
      else {
        cout<<"NO\n";
      }
    }
    else if("query"==op) {
      cout<<que[head]<<'\n';
    }
  }
}